package org.lc.kcjxzj.textcheck;

import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class AlgorithmDispatcher {
    private final CosineSimilarity cosine;
    private final JaccardSimilarity jaccard;
    private final LevenshteinDistance levenshtein;
    private final ConsecutiveSimilarity consecutive;

    public AlgorithmDispatcher(
        CosineSimilarity cosine,
        JaccardSimilarity jaccard,
        LevenshteinDistance levenshtein,
        ConsecutiveSimilarity consecutive
    ) {
        this.cosine = cosine;
        this.jaccard = jaccard;
        this.levenshtein = levenshtein;
        this.consecutive = consecutive;
    }

    /**
     * 计算相似度,暂时停用
     * @param text1
     * @param text2
     * @return
     */
    public float cosine(String text1, String text2) {
        /*
        if (!StringUtils.hasText(text1) || !StringUtils.hasText(text2)) {
            return 0.0f;
        }
        return (float) cosine.calculate(text1, text2);
        */
        return 0;
    }

    /**
     * 计算相似度,暂时停用
     * @param text1
     * @param text2
     * 
     */
    public float jaccard(String text1, String text2) {
        /*
        if (!StringUtils.hasText(text1) || !StringUtils.hasText(text2)) {
            return 0.0f;
        }
        return (float) jaccard.calculate(text1, text2);
        */
        return 0;
    }

    public float levenshtein(String text1, String text2) {
        if (!StringUtils.hasText(text1) || !StringUtils.hasText(text2)) {
            return 0.0f;
        }
        return (float) levenshtein.calculate(text1, text2);
    }

    public float consecutive(String text1, String text2) {
        if (!StringUtils.hasText(text1) || !StringUtils.hasText(text2)) {
            return 0.0f;
        }
        return (float) consecutive.calculate(text1, text2);
    }
}